<template>
  <div class="invent-treeManage">
    <div class="componentTopInv">
      <!-- <div style="padding-left: 15px" class="changeMore" @click="changeMore"><span class="iconfont icon-shaixuan"></span></div> -->
      <div class="changeMore">
            <div class="navTitle" @click="changeHome"><i class="el-icon-arrow-left icon"></i><span>设备管理</span></div>
            <div class="left">
              <div class="scan" :style="{transform: isAndriod?'translateY(1.5px)':'translateY(4px)'}">
                <!-- <span class="iconfont icon-shaixuan" @click="changeMore" style="font-size:20px;"></span> -->
                <iconSvg name="filter" w="19px" h="19px" @click.native="changeMore"></iconSvg>
              </div>
              <!-- <div class="scan" @click="scanAdd">
                <span style="font-size:20px;" class="iconfont">&#xe60a;</span>
              </div> -->
            </div>
            <div class="right">
              <div @click="changeHome" class="scan" :style="{transform: isAndriod?'translateY(-3.6px)':'translateY(-2.2px)'}">
                <span class="iconfont" style="font-size:22px;">&#xe607;</span>
              </div>
              <div @click="backToHomepage" class="scan backToHomepage" :style="{transform: isAndriod?'translateY(-3.5px)':'translateY(-3.5px)','margin-right':'18px'}">
                <span class="iconfont"   v-focusable @click="backToHomepage" style="font-size:17px;"><iconSvg name="home" w="20" h="20" style="transform: translateY(-2px);"  class="d_icon"></iconSvg></span>
              </div>
          </div>
        </div>
    </div>
    <div class="MoreData" v-if="showMore">
      <div class="deviceName">部件名称 <input type="text" placeholder="请输入部件名称" v-model="componentName"></div>
      <div class="deviceCode">部件编号 <input type="text" placeholder="请输入部件编号" v-model="componentCode"></div>
      <div class="deviceBtn">
        <div class="btnGroup">
        <button class="reserBtn" @click="reset">重置</button>
        <button class="overBtn" @click="overBtn">完成</button>
      </div>
      </div>
      <!-- <div @click="slideClassify">部件分类 <span>{{componentCls}} <font-awesome-icon :icon="['fa','chevron-down']" size="lg" /></span></div> -->
    </div>
    <!-- <div :class="styles" ref="category" style="width: 100%;height: 103px;padding: 10px 0;overflow: hidden;position: absolute">
      <div>
        <group>
          <radio :options="classify" v-model="radioValue" @on-change="change"></radio>
        </group>
      </div>
    </div> -->
    <!-- <div v-if="showMore" :class="maskStyle" v-show="show" @click="showVuePopup(false)"></div> -->
    <ic-header></ic-header>
    <div class="invent-box">
      <!-- <div class="number">共{{componentNum}}条记录</div>
      <div class="thead">
        <div class="name">部件名称</div>
        <div class="code">部件编号</div>
        <div class="item"  @click="leapfrogSort('stockNum', sort1, 1)">库存数量 <font-awesome-icon :icon="['fa','sort']" size="lg" /></div>
        <div class="item"  @click="leapfrogSort('safeNum', sort2, 2)">安全库存 <font-awesome-icon :icon="['fa','sort']" size="lg" /></div>
      </div> -->
      <div class="bscroll" ref="bscroll">
         <div class="bscroll-container">
            <mescroll-vue class="me_scroll" ref="mescroll" :down="mescrollDown" :up="mescrollUp" @init="mescrollInit">
              <div v-for="(item, index) in data" :key="index" class="invent-item" @click="invenInfo(item,index)">
                <div class="card">
                 <transition>
                    <div :class="{'active1':isShow1==index,'bg':true}">
                      <div class="header">
                        <div :class="{title:true,and:isAndriod}">名称：{{computedByteLen(item.name)>=maxLength?methodGetByteLen(item.name,maxLength-4):item.name}} <p class="more" @click.stop v-if="computedByteLen(item.name)>=maxLength"><label @click="openMore(item.name)">更多</label></p></div>
                        <!-- <div class="title">名称：{{computedByteLen(deviceInfo.deviceName)>=maxLength?methodGetByteLen(deviceInfo.deviceName,maxLength-4):deviceInfo.deviceName}} <p class="more" @click.stop v-if="computedByteLen(deviceInfo.deviceName)>=maxLength"><label @click="openMore(deviceInfo.deviceName)">更多</label></p></div> -->
                        <div :class="{numberRow:true,and:isAndriod}">编号：{{item.code}}</div>
                      </div>
                      <div :class="{inventoryRow:true,and:isAndriod}">
                        <div class="item">库存：{{item.stockNum}}件</div>
                        <div class="item">安全库存：{{item.safeNum}}件</div>
                      </div>
                    </div>
                  </transition>
                  </div>
                <!-- <span class="name">{{item.name}}</span>
                <span class="code">{{item.code}}</span>
                <span class="value">{{item.stockNum || item.stockNum == 0?item.stockNum:'-'}}</span>
                <span class="value">{{item.safeNum || item.safeNum == 0?item.safeNum:'-'}}</span> -->
              </div>
          <div class="mescroll-empty" v-if="isEmpty">
            <img class="empty-icon" src="/static/img/zwlr-icon.png">
            <p class="empty-tip">暂无内容</p>
        </div>
            </mescroll-vue>
        </div>
      </div>
    </div>
    <!-- <ic-footer></ic-footer> -->
    <button class="ewm" @touchstart="handleTouchstart"  @touchmove.stop="move" @touchend="handleTouchend" @click="scanAdd">扫一扫</button>
  </div>
</template>

<style scoped lang="less">
  @import '../../../styles/iconfont.css';
  // * { touch-action: none; }
  #app, .content{
    width: 100%!important;
    height: 100%!important;
  }
  .invent-treeManage{
    position: fixed;
    top:0px;
    width: 100%;
    height: 100%;
    background-color: #22233f;
    color: #fff;

  }
  // .componentTopInv{
  //   height: 8%;
  //   display: flex;
  //   line-height: 50px;
  //   font-size: 16px;
  // }
  // .componentTopInv div{flex: 1}
  // .componentTopInv div:last-child{text-align: right;padding-right: 15px;display: inline-block}
  // .componentTopInv img{
  //   width: 18px;
  //   height: 18px;
  // }

  .invent-box{
    width:100%;
    // height: 85%;
    background: none;
  }
  // .thead{
  //   border: 1px solid #494a5f;
  // }
  .invent-item, .thead{
    height: auto;
    line-height: normal;
    display: block;
    // border-bottom: 1px solid #C7C7C7;
  }
  .thead div, .invent-item span{flex: 1;text-align: center}
  .invent-item span:nth-child(1){
    overflow:hidden;
    text-overflow:ellipsis;
    white-space:nowrap;
    word-break:keep-all;
  }
  .invent-item span:nth-child(1){
    overflow:hidden;
    text-overflow:ellipsis;
    white-space:nowrap;
    word-break:keep-all;
  }
  .bscroll{
    width: 100%;
    height: calc(~"100% - 50px");
    overflow: scroll;
    position: fixed;
  }

  .category{
     width: 100%;
    height: 103px;
    padding: 10px 0;
    overflow: hidden;
    position: fixed;
    visibility: hidden;
    z-index: -10;
  }
  .category2{
     width: 100%;
    height: 103px;
    padding: 10px 0;
    overflow: hidden;
    position: fixed;
    top: 5.8rem;
    z-index: 999;
  }

  .setBtn{
    z-index: 999;
    background: #22233f;
    width: 100%;
    height: 50px;
    text-align: -webkit-right;
    padding: 20px 0 15px;
  }
  .setBtn2{
    z-index: 999;
    position: absolute;
    top: 9rem;
    background: #22233f;
    width: 100%;
    height: 50px;
    text-align: -webkit-right;
    padding: 20px 0 15px;
  }
  .deviceBtn{
    overflow: hidden;
    .btnGroup{
      margin: 0;
      text-align: right;
      display: flex;
      // height: 30px;
      // line-height: 30px;
      // width: fit-content;
      // padding:20px !important;
      float: right;
      button{
        display: inline-block;
        background:none;
      }
    }

  }
  .reserBtn{
    background: #3967DC;
    padding: 0 15px;
    border-bottom-left-radius: 15px;
    border-top-left-radius: 15px;
    border-right: 1px #22233f solid;
    border:none;
    color:#fff;
    font-size: 16px;
  }
  .overBtn{
    background: #3967DC;
    padding: 0 15px;
    border-bottom-right-radius: 15px;
    border-top-right-radius: 15px;
    border:none;
    color:#fff;
    font-size: 16px;
  }

  /* .weui-cells{
    background-color: #1e1f3c !important;
  } */
  .mask {
      position: fixed;
      top:39%;
      width: 100%;
      height: -webkit-fill-available;
      background-color: rgba(0, 0, 0, 0.3);
      transition: all 0.2s ease-in;
      z-index: 999;
      left:0px;
      right:0px;
  }
  .mask2 {
      position: absolute;
      top: 64%;
      width: 100%;
      height: -webkit-fill-available;
      background-color: rgba(0, 0, 0, 0.3);
      transition: all 0.2s ease-in;
      z-index: 999;
  }
  .weui-cells:before, .weui-cells:after{border: none!important;}
</style>
<style scoped lang="less">
  body{
    overflow: hidden;
  }
  .me_scroll {
    top: 120px;
  }
  .mescroll {
    /* position: fixed;
    bottom: 130px;
    height: 75%; */
    position: fixed;
    padding: 0 10px;
    box-sizing: border-box;
    top: 120px;
    bottom: 0;
    height: auto;
    background-color: #22233f;
  }

  .me_scroll .card{
    margin-bottom: 12px;
    text-align: left;
    // padding: 0 15px;
    .bg{
      background: #292A4D;
      border-radius: 4px;
      transition: background 0.3s ease-in-out !important;
      &.active1{
        background: #383A69;
      }
      .header{
        color: #fff;
        font-size: 17px;
        padding: 0 8px;
        position: relative;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        .title{
          padding-top: 10px;
          line-height: 22.5px;
          &.and{
            padding-top: 11px;
          }
        }
        .more{
          display: inline-block;
          color:#456DE6;
        }
        span{
          display: inline-block;
          position: absolute;
          top: 0;
          right: 8px;
          &.gz{
            color: #DD2306;
          }
          &.wjk{
            color: rgba(255, 255, 255, 0.6);
          }
          &.tz{
            color: #4FDBE5;
          }
          &.lx{
            color: #DD9710;
          }
          &.yz{
            color: #456DE6;
          }
        }
      }
      .numberRow{
        padding-bottom: 9px;
        font-size: 16px;
        line-height: 22.5px;
        color: rgba(255, 255, 255, 0.6);
      }
      .inventoryRow{
        font-size: 16px;
        color: rgba(255, 255, 255, 0.6);
        padding: 10px 8px;
        display: flex;
        &.and{
          padding-bottom: 12px;
        }
        .item{
          padding: 0 !important;
          flex: 1;
          &:nth-child(2){
            border-left: 0.026667rem solid #494a5f;
            text-align: right;
          }
        }
      }
    }
  }

  .bscroll-container{
    transform:unset ! important;
  }
  .MoreData{
      background: #22233f;
      position:fixed;
      width: 100%;
      height: auto;
      top: 50px;
      z-index: 999;
      .showClassifyInfo{
        margin: 0;
        height: 120px;
        overflow: auto;
      }
      div{
        font-size: 16px;
        line-height: 40px;
        color: #ffffff;
        margin: 10px;
        input{
          border-bottom: 1px solid rgba(0, 0, 0, 0.3);
          margin-left: 20px;
          text-align: left;
          color:rgba(255,255,255,.5);
          font-size: 16px;
          &::-webkit-input-placeholder{
            color:rgba(255,255,255,.5);
            font-size: 14px;
          }
        }
      }
      span{
        float: right;
        height: 40px;
        line-height: 40px;
        /*width: 50%;*/
        color: rgba(255,255,255,0.5);
        img{
          width: 20px;
          height: 20px;
          margin: 15px 0;
          float: right;
        }
      }
    }
    .number{
      line-height: 30px;
      padding-left: 15px;
      width: 100%;
      background-color: #22233f;
      color:#fff;
      // border-left: 1px solid #494a5f;
      // border-right: 1px solid #494a5f;
    }
  /****************导航icon*******************/
  .changeMore{
      display: flex;
      width: 100%;
      height: 50px;
      padding: 0 !important;
      margin: 0 !important;
      margin-bottom: 5px !important;
      box-sizing: border-box;
      border-bottom: 1px solid #494a5f;
      div{
        flex:1;
      }
      .left,.right{
        // float: left;
        // width: 49.7%;
        height: 100%;
        padding: 0 !important;
        margin: 0 !important;
        .scan{
          // float: left;
          // margin-left: 30%;
          margin-top: 11px;
          display: inline-block;
        }
        .backToHomepage{
          margin-top: 11px !important;
        }
      }
      .left{
        text-align: center;
      }
      .right{
        text-align: right;
          .scan{
            margin-right: 10px;
            &:nth-child(1){
              position: relative;
              &::before{
                content: "";
                width: .026667rem;
                height: 30%;
                background: hsla(0,0%,100%,.4);
                position: absolute;
                top: calc(~'50% + 1px');
                left: -14px;
                -webkit-transform: translateY(-50%);
                transform: translateY(-50%);
                border-left: 0.026667rem solid rgba(255, 255, 255, 0.1);
              }
            }
          }
      }
      .navTitle{
        white-space: nowrap;
        display: flex;
        text-align: center;
        color: #ffffff;
        span{
          font-size: 16px;
          display: inline-block;
          height: 50px;
          line-height: 50px;
        }
        .icon{
          font-size: 20px;
          margin-left:10px;
          display: inline-block;
          height: 50px;
          line-height: 50px;
          color: #ffffff;
        }
      }
      .left{
        // width: 49.8% !important;
        // border-right: 1px solid #494a5f;
      }
  }
  .mescroll-empty{
    padding-top: 50px;
    .empty-icon{
        width: 64px;
        height: 64px;
        margin-left: 22px;
    }
    .empty-tip{
        color: #4F77C0;
    }
  }
.ewm{
  position: fixed;
  right: 16px;
  bottom: 116px;
  width: 44px;
  height: 44px;
  outline: none;
  border: none;
  border-radius: 50%;
  background:rgba(69,109,230,0.4);
  color: #fff;
  font-size: 12px;
  line-height: 44px;
  text-align: center;
  user-select: none;
  z-index: 99;
  &:active{
    background: rgba(69,109,230,0.6);
  }
}
</style>

<script>
  import { XTable,ButtonTab, ButtonTabItem,Checklist, Radio, Group,AlertPlugin} from "vux";
  // import IcFooter from "../../common/ic-footer";
  import IcHeader from "../../common/ic-header";
  import BScroll from "better-scroll";
  import MescrollVue from "mescroll.js/mescroll.vue"
  let _this = null;
  export default {
    components: {
      AlertPlugin,
      XTable,
      // IcFooter,
      ButtonTab,
      ButtonTabItem,
      Checklist,
      BScroll,
      Radio,
      Group,
      MescrollVue,
      IcHeader,
    },
    data () {
      return {
        isAndriod:false,
        isSelectData:false,
        isShow1:-1,
        maxLength:24,
        isEmpty:false,
        radioShow: [],
        data: [],
        dataInfo:[],
        dataInfoBak:[],
        id: null,
        showMore: false,
        //部件分类
        componentCls: '请选择部件分类',
        //部件名称
        componentName: '',
        //部件编号
        componentCode: '',
        componentNum:'0',
        //部件分类信息展示 默认不展示
        showClassifyInfo: false,
        //分类信息
        classify: [],
        classifyInfo: [],
        radioValue: '',
        imgStyle: {
          display: 'block',
        },
        sort1: false,
        sort2: false,
        sortType: 'stockNum',
        show: false,
        styles: 'category',
        btnStyle: 'setBtn',
        maskStyle: 'mask',
        mescroll: null,
        mescrollDown: {
          use: true,
          warpClass: 'my-downwarp',
          htmlContent: '<p class="downwarp-progress mescroll-rotate"></p><p class="downwarp-tip">加载中...</p>',
          onMoving: this.onMoving,
          afterLoading: this.showTotalNum,
          offset: 60,
          textOutOffset: '松开刷新'
        },
        mescrollUp: {
          that: this,
          callback: this.upCallback,
          page: {
            num: 0,
            size: 20
          },
          htmlNodata: '<p class="upwarp-nodata">-- 暂无更多的数据 --</p>',
          noMoreSize: 5,
          toTop: {
            src: "./static/mescroll-totop.png",
            offset: 1000
          }
        },
      }
    },
    //返回首页的公共方法
    inject: ["backToHomepage"],
    methods: {
          // 判断是否安卓手机
    isAndriodDevice() {
      var u = navigator.userAgent;
      var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1;
      return isAndroid
		},
    openMore(val){
      this.$vux.alert.show({
        title: '标题',
        content: val,
        onShow () {
          console.log('Plugin: I\'m showing')
        },
        onHide () {
          console.log('Plugin: I\'m hiding')
        }
      })
      console.log(val)
    },
    methodGetByteLen(str, len) {
      // 如果字节的长度小于控制的长度，那么直接返回
      if (this.computedByteLen <= len) {
        return str
      }
      for (let i = Math.floor(len / 2); i < str.length; i++) {
        if (str.substr(0, i).replace(/[^\x00-\xff]/g, '01').length >= len) {
          // Math.floor(i / 2) * 这里是控制特殊情况的显示
          // 如 '一二aaa一二三四'，显示的结果就是 '一二aaa一...'
          return str.substr(0, Math.floor(i / 2) * 2) + '...'
        }
      }
    },
    // 获取字节的个数
    computedByteLen(val) {
      return val.replace(/[^\x00-\xff]/g, '01').length
    },
      move(e){
        let odiv = e.targetTouches[0];        //获取目标元素
        e.preventDefault();
        //用鼠标的位置减去鼠标相对元素的位置，得到元素的位置
        let top = odiv.clientY - odiv.target.offsetHeight / 2;
        let h = document.body.clientHeight
        let offsetBottom = h - odiv.clientY - odiv.target.offsetHeight/2;
        // console.log(top, odiv.clientY, h, offsetBottom)
        if (top <= 47) {
            top = 47
        } else if(offsetBottom <= 98) {
            return
        }
        //移动当前元素
        e.target.style.right = 16 + 'px';
        e.target.style.top = top + 'px';
      },
      handleTouchstart (e) { // 开始拖拽
        this.isbound = true
        this.isHidden = true
        console.log(document.getElementsByTagName('body')[0])
        let eleBody = document.getElementsByTagName('body')[0]
        eleBody.style.position = 'fixed'
        eleBody.style.width = '100vw'
        eleBody.style.height = '100vh'
        eleBody.style.top = 0
        eleBody.style.left = 0
      },
      handleTouchend (e) { // 拖拽结束
        e.target.style.right = 16 + 'px';
        this.isbound = false
        this.isHidden = false
        let eleBody = document.getElementsByTagName('body')[0]
        eleBody.style.position = 'relative'
        // eleBody.style.width = 'auto'
        // eleBody.style.height = 'auto'
        // eleBody.style.top = 'unset'
        // eleBody.style.left = 'unset'
      },
      showTotalNum(mescroll) {
        let di = JSON.stringify(this.dataInfo.slice(0,20))
        let diB = JSON.stringify(this.dataInfoBak.slice(0,20))
        let isNoUpdate = Object.is(di,diB)
        document.querySelector('.downwarp-content').style.display = 'none'
        let warp = document.getElementsByClassName('my-downwarp')[0]
        let totalBox = document.querySelector('.total_num_view')
        let p = document.createElement('p')
        p.setAttribute('class','total_num_view');
        if(this.isSelectData){
            p.innerHTML =  this.data.length>0?'筛选成功':'无设备信息'
        }else if (this.isEquals) {
            p.innerHTML =  `已是最新信息`
        } else {
            p.innerHTML =  isNoUpdate?'已是最新信息':`已为你加载${this.data.length}条信息`
        }
        if (totalBox == null) {
            warp.appendChild(p)
        } else {
            if (this.isEquals) {
                totalBox.innerHTML =  `已是最新信息`
            } else if(this.isSelectData){
                totalBox.innerHTML =  this.data.length>0?'筛选成功':'无设备信息'
          }else {
                totalBox.innerHTML = isNoUpdate?'已是最新信息':`已为你加载${this.data.length}条信息`
            }
            totalBox.style.display = 'block'
        }
        this.isSelectData = false;
        return 1500
      },
      onMoving(mescroll, rate, downHight ) {
        let totalBox = document.querySelector('.total_num_view')
        if (downHight > 0 && totalBox) {
            document.querySelector('.downwarp-content').style.display = 'block'
            totalBox.style.display = 'none'
        }
        if (mescroll.downProgressDom) {
            mescroll.downProgressDom.classList.remove('mescroll-rotate');

            var progress = 360 * rate;
            mescroll.downProgressDom.style.webkitTransform = 'rotate(' + progress + 'deg)';
            mescroll.downProgressDom.style.transform = 'rotate(' + progress + 'deg)';
        }
      },
      changeHome(){
        this.$router.push({path: '/manage'});
      },
      getComponentNum: function(){
        let param = {
          departmentId: 0,
          componentName:this.componentName,
          componentCode:this.componentCode,
        }
        this.$http(this.$API.getDeviceNum, param,true).then((res) => {
        if (res) {
          this.componentNum = res.componentNum;
          }
        });
      },
      //入库  (暂时注释)
      invenInfo(data,index) {
        this.isShow1 = index
        this.$store.commit("setRadio", data);
        setTimeout(()=>{
          this.$router.push({
            name: "inventoryManage",
            query: { id: data.id, name: "listInfo" }
          });
        },200)
      },
      //获取列表
      getList() {
        var url = this.$API.inventList;
        this.$http(url, {}, true).then(res => {
          for (var i = 0; i < res.length; i++) {
            this.radioShow.push(true);
            if(this.classify.indexOf(res[i].catName) == -1){
                this.classify.push(res[i].catName);
                this.classifyInfo.push({catId:res[i].catId, catName:res[i].catName});
            }
          }
          this.isEmpty = res.length>0?false:true
          this.data = res;
          this.data = this.data.concat(res);
          this.data = this.data.concat(res);
          this.data = this.data.concat(res);
          this.data = this.data.concat(res);
          this.dataInfo = this.data
        });
      },
      //展开更多
      changeMore: function () {
        this.isSelectData = true
        this.showMore = true;
        this.show = true;
      },
      reset: function(){
        this.componentName = '';
        this.componentCode = '';
        this.componentCls = '请选择部件分类';
      },

      // 筛选
      overBtn: function () {
        this.isSelectData = true;
        setTimeout(() => {
          this.showMore = false;
        }, 300);
        this.mescroll.resetUpScroll(true);
        this.getComponentNum();
      },
      slideClassify: function () {
        this.show = true;
        this.showClassifyInfo = true;
        this.styles = 'category2';
        this.btnStyle = 'setBtn2';
        this.maskStyle = 'mask2';
        this.Scroll = new BScroll(this.$refs.category,{click: true, tap: true});
      },
      change(val, label) {
          this.componentCls = val;
          this.styles = 'category';
          this.btnStyle = 'setBtn';
          this.maskStyle = 'mask';
          // this.imgStyle.display = "none";
          // this.showClassifyInfo = false;
      },
      leapfrogSort(type, sorted, sortnumber) {
          if (sortnumber === 1){
            if (sorted === false) {
              this.sort1 = true;
              this.sortType = type;
              this.data.sort(this.compare(type));
            }else{
              this.sort1 = false;
              this.sortType = type;
              this.data.sort(this.compare2(type));
            }
          }else {
            if (sorted === false) {
              this.sort2 = true;
              this.sortType = type;
              this.data.sort(this.compare(type));
            }else{
              this.sort2 = false;
              this.sortType = type;
              this.data.sort(this.compare2(type));
            }
          }
        },
      compare(attr) {
        return function(a,b){
          var x = a[attr];
          var y = b[attr];
          return ((x>y)?-1:(x<y)?1:0)
        }
      },
      compare2(attr) {
        return function(a,b){
          var x = a[attr];
          var y = b[attr];
          return ((x<y)?-1:(x>y)?1:0)
        }
      },
      showVuePopup(flag) {
        if (flag === false){
          this.change();
          this.showMore = false;
        }
        this.show = flag;
      },
      mescrollInit(mescroll) {
        this.mescroll = mescroll;
      },
      upCallback(page, mescroll) {
        let params = {
          componentName: this.componentName,
          componentCode: this.componentCode,
          pageNum: page.num,
          pageSize: page.size,
        };
        this.dataInfoBak = JSON.parse(JSON.stringify(this.dataInfo))
        this.$http(this.$API.inventList, params, true).then(res => {
          if (res) {
            let data = res;
            if (page.num === 1) {
              this.data = [];
            }
            this.data = this.data.concat(data);
            this.isEmpty = this.data.length>0?false:true
            this.dataInfo = this.data;
            this.$nextTick(() => {
              mescroll.endSuccess(data.length);
            });
          } else {
            this.mescroll.endErr();
          }
        });
      },

      // 扫码二维码
      scanAdd: function () {
        let strUrl = '';
        wx.ready(()=>{
            wx.scanQRCode({ // 微信扫一扫接口
            desc: 'scanQRCode desc',
            needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
            scanType: ['qrCode', 'barCode'], // 可以指定扫二维码还是一维码，默认二者都有
            success: function (res) {
              //扫码之后返回设备信息，获取设备id，跳转对应页面
              strUrl = res.resultStr;
              let name="state";
              let reg = new RegExp('(^|&)' + name + '=([^&]*)(#|$)', 'i');
              let r = strUrl.substr(1).match(reg);
              let id = '';
              if (r != null) {
                id =  r[2].split("#")[0];
              }
              if(strUrl.indexOf(location.hostname) != -1){
                window.location.href = _this.url + '/#/operaionManage/spotCheck/componentCheck?deviceId=' + id;
              }else{
                this.$commom.alert('请输入正确的手机号码');
              }
            }
          })
        }).catch((err)=>{
          console.log("err:===>",err)
        });
      },
      getDomin: function(){
        this.url = window.location.protocol +'//'+ window.location.host;
      }

    },
    beforeRouteEnter(to, from, next) {
      next(vm => {
        vm.$refs.mescroll && vm.$refs.mescroll.beforeRouteEnter();
        vm.isShow1 = -1;
      });
    },
    beforeRouteLeave(to, from, next) {
      this.$refs.mescroll && this.$refs.mescroll.beforeRouteLeave();
      next();
    },
    created() {
      _this = this;
      this.isAndriod = this.isAndriodDevice()
      console.log( this.isAndriod )
      this.getDomin();
      let localUrl = location.href.split('#')[0];
      // 获取微信签名
      this.$http(this.$API.getWxSign,{url:encodeURIComponent(localUrl)}, true).then((res) => {
        if (res){
          wx.config({
            debug: false,
            appId: res.appId, // 必填,公众号的唯一标识
            timestamp: res.timestamp, // 必填,生成签名的时间戳
            nonceStr: res.nonceStr, // 必填,生成签名的随机串
            signature: res.signature, // 必填,签名
            jsApiList: ['scanQRCode',] // 必填,需要使用的JS接口列表
          });
            /* 处理失败验证 */
          wx.error(function (res) {
            console.log("res:====>",res);
          // config 信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名
          });
        }
      });
      this.$store.commit("setRadio", null);
      this.getComponentNum();
    },
    mounted(){
      this.$nextTick(() => {
        this.Scroll = new BScroll(this.$refs.mescroll,{click: true, tap: true});
        })
      },

    }

</script>
